package com.lagou.sqlSession;

import com.lagou.configuration.XmlConfigurationBuilder;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author dcwu5
 * @date 2020-05-23
 * @description
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {
        // 第一：使用dom4j解析配置文件将解析出来的内容封装到Configuration中
        XmlConfigurationBuilder xmlConfigurationBuilder = new XmlConfigurationBuilder();
        Configuration configuration = xmlConfigurationBuilder.parseConfig(inputStream);
        // 第二：创建SQLSessionFactory对象 工厂类
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }
}
